package com.itheima.paymentdemo.controller;

import com.itheima.paymentdemo.entity.OrderInfo;
import com.itheima.paymentdemo.enums.OrderStatus;
import com.itheima.paymentdemo.service.OrderInfoService;
import com.itheima.paymentdemo.vo.R;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 功能：订单
 * 作者：大风
 * 日期：2024/9/29 10:14
 */
@CrossOrigin //开放前端的跨域访问
@RestController
@RequestMapping("/api/order-info")
@Api(tags = "网站微信支付订单API")
@Slf4j  //该日志注释是lombok提供的
public class OrderInfoController {

    @Resource
    private OrderInfoService orderInfoService;

    @GetMapping("/list")
    public R list(){
        List<OrderInfo> list = orderInfoService.listOrderByCreateTimeDesc();
        return R.ok().data("list",list);
    }

    /**
     *  根据订单号查询本地订单状态
     *  当订单状态为支付成功后 前端页面的二维码需要变为支付成功通知
     * @param orderNo
     * @return
     */
    @GetMapping("query-order-status/{orderNo}")
    public R queryOrderStatus(@PathVariable String orderNo){
        String orderStatus = orderInfoService.getOrderStatus(orderNo);
        if(OrderStatus.SUCCESS.getType().equals(orderStatus)){
            return R.ok().setMessage("支付成功");
        }
        return R.ok().setCode(101).setMessage("支付中......");

    }
}
